//
//  Ugc_Receive_SystemCell_WX.m
//  ZITHER
//
//  Created by weixin on 2018/9/28.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "Ugc_Receive_SystemCell_WX.h"

#define kGAP 10
#define kAvatar_Size 40

@implementation Ugc_Receive_SystemCell_WX


- (void)awakeFromNib {
    [super awakeFromNib];
    //    self.backgroundColor = [UIColor randomColor];
    [self setBorderWithHiddem:NO Color:[UIColor colorWithHex:@"eeeeee"] width:1 Radius:0];
    [self.viewBorder mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.left.equalTo(self).offset(0);
        make.right.equalTo(self).offset(0);
        make.bottom.equalTo(self).offset(-10);
    }];
    [self setUI];
    [self defaultConfiguration];
    [self massonry];
}

-(void)setUI{
    [self addSubview:self.labMsgStatus];
    [self addSubview:self.PicUser];
    [self addSubview:self.labUserName];
    [self addSubview:self.labContent];
    [self addSubview:self.time];
}

-(void)defaultConfiguration{
    
    
    self.labUserName.text =@"系统通知";
    self.labUserName.font =  [UIFont fontWithName:@"PingFangSC-Medium" size:14];
    self.labUserName.textColor = [UIColor colorWithHex:@"333333"];
    

    self.labContent.textColor = [UIColor colorWithHex:@"333333"];
    self.labContent.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15];
    self.labContent.numberOfLines = 2;
    
    //    self.time.text =@"3分钟";
    self.time.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    self.time.textColor = [UIColor colorWithHex:@"999999"];

    
    [self.PicUser setCornerRadiusWithRadius:20 isMasks:YES];
    [self.PicUser setBorderWithColor:[UIColor blackColor] width:0.5];
    
}

-(void)massonry{
    
    [self.labMsgStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(14);
    }];
    
    [self.PicUser mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labMsgStatus.mas_bottom).offset(30);
        make.left.equalTo(self).offset(14);
        make.height.width.mas_equalTo(40);
    }];
    //    self.self.labUserName.hidden = YES;
    
    [self.labUserName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.PicUser.mas_top).offset(2);
        make.left.equalTo(self.PicUser.mas_right).offset(12);
    }];
    //    self.labContent.hidden = YES;
    
    //最多6航
    [self.labContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.time.mas_bottom).offset(8);
        make.left.equalTo(self.PicUser.mas_right).offset(12);
        make.right.equalTo(self).offset(-14);
        make.bottom.equalTo(self).offset(-20);
    }];
    
    //    self.time.hidden = YES;
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.PicUser.mas_bottom).offset(0);
        make.left.equalTo(self.PicUser.mas_right).offset(12);
        make.height.mas_equalTo(12);
    }];

    
    //
    //
    //    //右边布局 优先顺序 该创作已删除  图片 内容
    //    @property (weak, nonatomic) IBOutlet UILabel *del1;
    //    @property (weak, nonatomic) IBOutlet UILabel *del2;
    //
    //    @property (weak, nonatomic) IBOutlet UIImageView *picUgc;
    //
    //    @property (weak, nonatomic) IBOutlet UILabel *labUgcContent;
}

-(UIImageView *)PicUser{
    if (!_PicUser) {
        _PicUser = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _PicUser.image = [UIImage imageNamed:@"消息_系统通知头像"];
        _PicUser.contentMode = 2;
        [_PicUser setCornerRadiusWithRadius:20 isMasks:YES];
        _PicUser.clipsToBounds = YES;
    }
    return _PicUser;
}

-(UILabel *)labUserName{
    if (!_labUserName) {
        _labUserName = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _labUserName;
}

-(UILabel *)labContent{
    if (!_labContent) {
        _labContent = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _labContent;
}

-(UILabel *)time{
    if (!_time) {
        _time = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _time;
}

-(UILabel *)labMsgStatus{
    if (!_labMsgStatus) {
        _labMsgStatus = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        _labMsgStatus.font = [UIFont fontWithName:@"Helvetica-Bold" size:22];
    }
    return _labMsgStatus;
}

-(void)setTypeMsgStatus:(NSString *)typeMsgStatus{
    _typeMsgStatus = typeMsgStatus;
    self.labMsgStatus.text = typeMsgStatus;
    
    if (typeMsgStatus.length == 0) {
        self.labMsgStatus.hidden = YES;
        [self.PicUser mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.labMsgStatus.mas_bottom).offset(0);
        }];
    }else{
        [self.PicUser mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.labMsgStatus.mas_bottom).offset(30);
        }];
        self.labMsgStatus.hidden = NO;
    }
}

-(void)setModelSon:(UgcReceiveModelSon *)modelSon{
    _modelSon = modelSon;
    
    /** 消息类型（1:点赞  2:评论 3:回复评论）*/
    if ([modelSon.msgType isEqualToString:@"1"]) {
        self.labContent.text = @"赞了你的创作";
    }else if ([modelSon.msgType isEqualToString:@"0"]){
        self.labContent.text = modelSon.msg;
    }else{
        [self configComment:modelSon.msgType];
    }
    
    self.time.text = [modelSon.createTime convertCurrentTime];
    
    //    /** 消息状态（0：未查看， 1：已查看）*/
    //    @property (nonatomic, copy) NSString *msgStatus;
    //
    //    /** 详情页 ID */
    //    @property (nonatomic, copy) NSString *relId;
    //
    //    /** 跳转到个人主页 ID */
    //    @property (nonatomic, copy) NSString *sendUserId;
    
    
}



/** type(2: 评论创作 3: 回复其他人) */
-(void)configComment:(NSString*)type{
    
    //两种状态 一种自己回复 一种是回复其他人
    NSString *str = nil;
    if ([type isEqualToString:@"2"]){
        //不需要展示回复人
        str= [NSString stringWithFormat:@"评论了你的创作 %@",self.modelSon.msg];
        
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *muStyle = [[NSMutableParagraphStyle alloc] init];
        
        if ([text.string isMoreThanOneLineWithSize:CGSizeMake(kScreenW-kGAP-kAvatar_Size-2*kGAP, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpaceing:5.0]) {//margin
            muStyle.lineSpacing = 5.0;//设置行间距离
        }else{
            muStyle.lineSpacing = CGFLOAT_MIN;//设置行间距离
        }
        
        [text addAttribute:NSParagraphStyleAttributeName value:muStyle range:NSMakeRange(0, text.length)];
        
        [text addAttribute:NSForegroundColorAttributeName
                     value:[UIColor blackColor]
                     range:NSMakeRange(0, 7)];
        [text addAttribute:NSFontAttributeName
                     value:[UIFont fontWithName:@"Helvetica-Bold" size:12]
                     range:NSMakeRange(0,7)];
        
        self.labContent.attributedText = text;
    }else if ([type isEqualToString:@"3"]){
        str= [NSString stringWithFormat:@"回复你的评论 %@",self.modelSon.msg];
        
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *muStyle = [[NSMutableParagraphStyle alloc] init];
        
        if ([text.string isMoreThanOneLineWithSize:CGSizeMake(kScreenW-kGAP-kAvatar_Size-2*kGAP, CGFLOAT_MAX) font:[UIFont systemFontOfSize:13.0] lineSpaceing:5.0]) {//margin
            muStyle.lineSpacing = 5.0;//设置行间距离
        }else{
            muStyle.lineSpacing = CGFLOAT_MIN;//设置行间距离
        }
        
        [text addAttribute:NSParagraphStyleAttributeName value:muStyle range:NSMakeRange(0, text.length)];
        
        [text addAttribute:NSForegroundColorAttributeName
                     value:[UIColor blackColor]
                     range:NSMakeRange(0, 6)];
        [text addAttribute:NSFontAttributeName
                     value:[UIFont fontWithName:@"Helvetica-Bold" size:12]
                     range:NSMakeRange(0,6)];
        
        self.labContent.attributedText = text;
    }
}

@end
